<template>
  <view class="viewport">
    <!-- #ifndef MP-TOUTIAO -->
    <!-- 自定义导航栏 -->
    <uni-nav-bar class="uni-nav-bar" background-color="rgba(255,255,255,0)" :border="false" :statusBar="true"
      @clickLeft="goBack">
      <template #left>
        <view class="icon-arrow-left"></view>
      </template>
      <template #default>
        <view class="title">会员中心</view>
      </template>
    </uni-nav-bar>
    <!-- #endif -->
    <!-- 抖音小程序顶部导航 -->
    <!-- #ifdef MP-TOUTIAO -->
    <view class="toutiao-nav-bar">
      <view class="status-bar"></view>
      <view class="title-container">
        <view class="title">会员中心</view>
      </view>
    </view>
    <!-- #endif -->
    <uv-tabs :list="learnBaseTypes" lineColor="#b35936" lineWidth="40rpx" lineHeight="6rpx" :activeStyle="{
      color: '#292522',
      fontSize: '36rpx',
      fontWeight: 'bold',
      transform: 'scale(1.05)'
    }" :inactiveStyle="{
      fontSize: '28rpx',
      color: '#292522',
      transform: 'scale(1)'
    }" itemStyle=" height: 90rpx;" :scrollable="false" :current="activeIndex" @change="tabsChange"></uv-tabs>
    <swiper class="swiper" :current="activeIndex" @change="swiperChange">
      <swiper-item v-if="learnBaseTypes?.find(item => item.code === 'km1')">
        <Subject base-type="km1"></Subject>
      </swiper-item>
      <swiper-item>
        2
      </swiper-item>
      <swiper-item>
        3
      </swiper-item>
      <swiper-item v-if="learnBaseTypes?.find(item => item.code === 'km4')">
        <Subject base-type="km4"></Subject>
      </swiper-item>
    </swiper>
  </view>
</template>

<script lang="ts" setup>
  import { ref } from 'vue'
  import { useLearnBaseTypes } from '@/composables/LearnBase'
  import Subject from './components/Subject.vue'

  // #ifdef MP-TOUTIAO
  // 获取小程序下胶囊按钮的布局位置信息
  let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  // 上边界坐标，单位：px
  let top = (menuButtonInfo.top - 10) + 'px'
  const statusBarHeight = ref(top)
  // 高度，单位：px
  let height = (menuButtonInfo.height + 20) + 'px'
  const titleHeight = ref(height)
  // #endif

  // 选项卡数据列表
  const { learnBaseTypes } = useLearnBaseTypes()
  const activeIndex = ref<number>(0)
  // tabs通知swiper切换
  const tabsChange = (item: any) => {
    activeIndex.value = item.index
  }

  // swiperChange
  const swiperChange = (e: UniHelper.SwiperOnChangeEvent) => {
    activeIndex.value = e.detail.current
  }
  //退出
  const goBack = () => {
    uni.navigateBack()
  }
</script>

<style lang="scss" scoped>
  @import '@/pagesMember/static/imgVars.scss';

  .viewport {
    display: flex;
    flex-direction: column;
    background: #f8f8f8;
    background-image: url($member-center-page-bg);
    background-size: 100% auto;
    background-repeat: no-repeat;
  }

  // 自定义导航栏
  .uni-nav-bar {
    .icon-arrow-left {
      font-size: 18px;
      font-weight: bold;
    }

    .title {
      flex: 1;
      align-self: center;
      text-align: center;
      font-size: 18px;
      font-weight: bold;
    }
  }

  /* #ifdef MP-TOUTIAO */
  // 抖音自定义导航栏
  .toutiao-nav-bar {

    // 顶部占位
    .status-bar {
      width: 100vw;
      height: v-bind(statusBarHeight);
    }

    // 标题行
    .title-container {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;
      height: v-bind(titleHeight);

      .title {
        // margin-left: 40rpx;
        font-size: 18px;
      }
    }
  }

  /* #endif */

</style>
